﻿using CC.Yacht.Messages;

namespace CC.Yacht.Utilities
{
    public static class MessageHelper
    {
        /// <summary>
        /// Resets the ErrorId and ErrorType on this <see cref="T"/>.
        /// </summary>
        /// <typeparam name="T">The type of this response.</typeparam>
        /// <param name="messageResponse">This response.</param>
        public static void ClearError<T>(this T messageResponse) where T : BaseResponse, new()
        {
            messageResponse.ErrorId = 0;
            messageResponse.ErrorType = ErrorType.None;
        }

        /// <summary>
        /// Creates a new response with <see cref="ErrorType.Unknown"/> specified.
        /// </summary>
        /// <typeparam name="T">The type of this response.</typeparam>
        /// <returns>A new response with <see cref="ErrorType.Unknown"/> specified.</returns>
        public static T CreateResponse<T>() where T : BaseResponse, new()
        {
            return CreateResponse<T>(ErrorType.Unknown);
        }

        /// <summary>
        /// Creates a new response with the specified <see cref="ErrorType"/>.
        /// </summary>
        /// <typeparam name="T">The type of this response.</typeparam>
        /// <param name="errorType">The <see cref="ErrorType"/>.</param>
        /// <returns>A new response with the specified <see cref="ErrorType"/>.</returns>
        public static T CreateResponse<T>(ErrorType errorType) where T : BaseResponse, new()
        {
            return new T { ErrorType = errorType };
        }
    }
}
